import 'package:flutter/material.dart';
import 'package:fijkplayer/fijkplayer.dart';
import 'package:x3_component_core/x3_component_core.dart';

class FijkVideoPlayerScreen extends StatefulWidget {
  final String videoUrl;
  final bool isNotShowTitle;
  final Function(FijkPlayer player) callback;

  FijkVideoPlayerScreen({@required this.videoUrl, this.callback, this.isNotShowTitle = false});

  @override
  _FijkVideoPlayerScreenState createState() => _FijkVideoPlayerScreenState();
}

class _FijkVideoPlayerScreenState extends State<FijkVideoPlayerScreen> {
  final FijkPlayer player = FijkPlayer();

  @override
  void initState() {
    super.initState();
    player.setDataSource(widget.videoUrl, autoPlay: true, showCover: true);
    if (widget.callback != null) widget.callback(player);
  }

  @override
  void dispose() {
    super.dispose();
    player?.release();
  }

  @override
  Widget build(BuildContext context) {
    return BaseScaffoldComponent(
      title: widget.isNotShowTitle ? null : "",
      child: Center(
        child: FijkView(width: double.infinity, height: double.infinity, color: Colors.white, player: player),
      ),
    );
  }
}
